import numpy as np
import pandas as pd
from qtorch.strategy import Strategy

class MACDStrategy(Strategy):
    """MACD策略（快线12/慢线26/信号9）"""
    def __init__(self, fast=12, slow=26, signal=9):
        self.fast = fast
        self.slow = slow
        self.signal = signal
        
    def generate_signals(self, prices):
        ema_fast = prices.ewm(span=self.fast).mean()
        ema_slow = prices.ewm(span=self.slow).mean()
        macd = ema_fast - ema_slow
        signal_line = macd.ewm(span=self.signal).mean()
        
        signals = np.where(macd > signal_line, 1, -1)
        return signals.astype(int)